Refactor show-next-page
authorjustbur <justin@burkett.cc>
Sat, 3 Oct 2015 17:41:00 +0000 (13:41 -0400)
committerjustbur <justin@burkett.cc>
Sat, 3 Oct 2015 17:41:00 +0000 (13:41 -0400)
which-key.el

index f2fe6c5191881a782df0697228c08af7e85acb9d..37a1412b96d65bc2bc92431f6fef643f0c6fc397 100644 (file)
@@ -1318,49 +1318,39 @@ enough space based on your settings and frame size." prefix-keys)
   "Show the next page of keys.
 Will force an update if called before `which-key--update'."
   (interactive)
-  (if (and which-key--current-page-n
-           which-key--on-last-page
-           which-key-use-C-h-for-paging
-           which-key-prevent-C-h-from-cycling)
-      (progn
-        (which-key--hide-popup-ignore-command)
-        (which-key--stop-timer)
-        (funcall which-key--prefix-help-cmd-backup)
-        (which-key--start-timer))
-    (let* ((next-event-if-showing
-            ;; forces event into current key sequence
-            (mapcar (lambda (ev) (cons t ev))
-                    (which-key--current-key-list)))
-           (keysbl
+  (cond
+   ;; on last page and want default C-h behavior
+   ((and which-key--current-page-n
+         which-key--on-last-page
+         which-key-use-C-h-for-paging
+         which-key-prevent-C-h-from-cycling)
+    (which-key--hide-popup-ignore-command)
+    (which-key--stop-timer)
+    (funcall which-key--prefix-help-cmd-backup)
+    (which-key--start-timer))
+   ;; No which-key buffer showing
+   ((null which-key--current-page-n)
+    (let* ((keysbl
             (vconcat (butlast (append (this-single-command-keys) nil))))
-           (next-event-if-not-showing
-            (mapcar (lambda (ev) (cons t ev)) (listify-key-sequence keysbl)))
-           (next-page
-            (if which-key--current-page-n (1+ which-key--current-page-n) 0)))
-      (cond
-       ;; buffer not showing
-       ((null which-key--current-page-n)
-        (which-key--stop-timer)
-        (setq unread-command-events next-event-if-not-showing)
-        (which-key--create-buffer-and-show keysbl)
-        (which-key--start-timer))
-       (t
-        (which-key--stop-timer)
-        (setq unread-command-events next-event-if-showing)
-        (if which-key--last-try-2-loc
-            (let ((which-key-side-window-location which-key--last-try-2-loc))
-              (which-key--show-page next-page))
-          (which-key--show-page next-page))
-        (which-key--start-paging-timer))))))
-
-;; (defun which-key-show-first-page ()
-;;   "Show the first page of keys."
-;;   ;; (which-key--stop-timer)
-;;   ;; (setq which-key--prefix-help-cmd-backup prefix-help-command
-;;   ;;       prefix-help-command 'which-key-show-next-page)
-;;   (which-key--show-page 0)
-;;   )
-;;   ;; (which-key--start-paging-timer))
+           (next-event
+            (mapcar (lambda (ev) (cons t ev)) (listify-key-sequence keysbl))))
+      (which-key--stop-timer)
+      (setq unread-command-events next-event)
+      (which-key--create-buffer-and-show keysbl)
+      (which-key--start-timer)))
+   ;; which-key buffer showing. turn page
+   (t
+    (let ((next-event
+           (mapcar (lambda (ev) (cons t ev)) (which-key--current-key-list)))
+          (next-page
+           (if which-key--current-page-n (1+ which-key--current-page-n) 0)))
+      (which-key--stop-timer)
+      (setq unread-command-events next-event)
+      (if which-key--last-try-2-loc
+          (let ((which-key-side-window-location which-key--last-try-2-loc))
+            (which-key--show-page next-page))
+        (which-key--show-page next-page))
+      (which-key--start-paging-timer)))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Update
@@ -1401,22 +1391,24 @@ Finally, show the buffer."
 
 (defun which-key--update ()
   "Function run by timer to possibly trigger `which-key--create-buffer-and-show'."
-  ;; Do not display the popup if a command is currently being executed
-  (unless this-command
-    (let ((prefix-keys (this-single-command-keys)))
-      ;; (when (> (length prefix-keys) 0)
-      ;;  (message "key: %s" (key-description prefix-keys)))
-      ;; (when (> (length prefix-keys) 0)
-      ;;  (message "key binding: %s" (key-binding prefix-keys)))
-      (when (and (> (length prefix-keys) 0)
-                 (or
-                  (keymapp (key-binding prefix-keys))
-                  ;; Some keymaps are stored here like iso-transl-ctl-x-8-map
-                  (keymapp (which-key--safe-lookup-key key-translation-map prefix-keys))
-                  ;; just in case someone uses one of these
-                  (keymapp (which-key--safe-lookup-key function-key-map prefix-keys)))
-                 (not which-key-inhibit))
-        (which-key--create-buffer-and-show prefix-keys)))))
+  (let ((prefix-keys (this-single-command-keys)))
+    ;; (when (> (length prefix-keys) 0)
+    ;;  (message "key: %s" (key-description prefix-keys)))
+    ;; (when (> (length prefix-keys) 0)
+    ;;  (message "key binding: %s" (key-binding prefix-keys)))
+    (when (and (> (length prefix-keys) 0)
+               (or (keymapp (key-binding prefix-keys))
+                   ;; Some keymaps are stored here like iso-transl-ctl-x-8-map
+                   (keymapp (which-key--safe-lookup-key
+                             key-translation-map prefix-keys))
+                   ;; just in case someone uses one of these
+                   (keymapp (which-key--safe-lookup-key
+                             function-key-map prefix-keys)))
+               (not which-key-inhibit)
+               ;; Do not display the popup if a command is currently being
+               ;; executed
+               (null this-command))
+      (which-key--create-buffer-and-show prefix-keys))))
 
 ;; Timers